package ioperations;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2024-08-02
 * Time: 19:12
 */
public class ReturnOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("您要归还的书籍名称：");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();
        for (int i = 0; i < bookList.usedSize; i++) {
            if(bookName.equals(bookList.books[i].getName())){
                if(bookList.books[i].isBorrowed() == true){

                    bookList.books[i].setBorrowed(false);
                    System.out.println("《" + bookList.books[i].getName() + "》" + "归还成功！");
                    return;
                }else{
                    System.out.println("《" + bookList.books[i].getName() + "》"+ "未借阅！");
                    return;
                }
            }
        }
        System.out.println("数据非法，请检查您的拼写正确性");
    }
}
